package com.hurui.xiaoming.adapter;

import android.content.Context;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.PagerAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.hurui.xiaoming.R;

import java.util.List;

/**
 * Created by hurui on 2017/7/16.
 */

public class ViewPagerAdapter extends FragmentPagerAdapter {

    private List<Fragment> fragments ;

    private Context context ;

    private List<String> titles ;

    public ViewPagerAdapter(FragmentManager fm , Context context , List<Fragment> fragments , List<String> title) {
        super(fm);
        this.fragments = fragments ;
        this.context = context ;
        this.titles = title ;
    }

    @Override
    public Fragment getItem(int position) {
        return fragments.get(position);
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return super.getPageTitle(position);
    }

    @Override
    public int getCount() {
        return fragments.size();
    }

    public View getTabView(int position){
        View view = LayoutInflater.from(context).inflate(R.layout.tab_title_view , null);
        TextView tab_tv = (TextView) view.findViewById(R.id.tab_tv);
        tab_tv.setText( titles.get(position) );
        return view ;
    }
}
